package com.laowang.project.monitor.mapper;

import java.util.Date;
import java.util.List;

import com.laowang.common.utils.StringUtils;
import com.laowang.project.monitor.domain.SysJob;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

/**
 * 调度任务信息 数据层
 * 
 * @author laowang
 */
public interface SysJobMapper extends Mapper<SysJob>
{
    /**
     * 查询调度任务日志集合
     * 
     * @param job 调度信息
     * @return 操作日志集合
     */
    default List<SysJob> selectJobList(SysJob job) {
        Example example = new Example(SysJob.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(job.getJobName())) {
            criteria.andLike("jobName", "%" + job.getJobName() + "%");
        }
        if (StringUtils.isNotEmpty(job.getJobGroup())) {
            criteria.andEqualTo("jobGroup", job.getJobGroup());
        }
        if (StringUtils.isNotEmpty(job.getStatus())) {
            criteria.andEqualTo("status", job.getStatus());
        }
        if (StringUtils.isNotEmpty(job.getInvokeTarget())) {
            criteria.andLike("invokeTarget", "%" + job.getInvokeTarget() + "%");
        }
        return selectByExample(example);
    }

    /**
     * 修改调度任务信息
     * 
     * @param job 调度任务信息
     * @return 结果
     */
    default int updateJob(SysJob job) {
        job.setUpdateTime(new Date());
        return updateByPrimaryKeySelective(job);
    }

    /**
     * 新增调度任务信息
     * 
     * @param job 调度任务信息
     * @return 结果
     */
    default int insertJob(SysJob job) {
        job.setCreateTime(new Date());
        return insertSelective(job);
    }
}
